//
//  SCHomeBMSHView.m
//  shangcheng
//
//  Created by Jie Jie on 2019/6/17.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCHomeBMSHView.h"

@interface SCHomeBMSHView()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong) UITableView *tabel_view;
@property (nonatomic , strong) UIButton *fb_button;

@end

@implementation SCHomeBMSHView
-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if(self){

        UIView *bg_view = [[UIView alloc] initWithFrame:CGRectMake(9, 0, kScreenW - 9*2, k_bmsh_view_h)];
        bg_view.layer.masksToBounds = YES;
        bg_view.layer.cornerRadius = 2;
        bg_view.backgroundColor = [UIColor whiteColor];
        [self addSubview:bg_view];
        
        [bg_view addSubview:self.tabel_view];
        [bg_view addSubview:self.fb_button];
        [self add_masonry];
    }
    return self;
}

#pragma mark 私有方法
-(void)add_masonry{
    
    CGFloat button_w = 57;
    CGFloat button_y = (k_bmsh_view_h - button_w) * 0.5;
    CGFloat button_space = 18;
    CGFloat table_w = kScreenW - 9*2 - button_w - button_space*2;
    
    [self.tabel_view mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(table_w);
    make.right.mas_equalTo(self.fb_button.mas_left).mas_offset(-button_space);
        make.height.mas_equalTo(k_bmsh_view_h);
       
        
    }];
    
    [self.fb_button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(button_y);
        make.width.and.height.mas_equalTo(button_w);
        make.right.mas_equalTo(-button_space);
        
    }];
    
    UIImageView *image_v = [[UIImageView alloc] init];
    image_v.image = [UIImage imageNamed:@""];
    [self.fb_button addSubview:image_v];
    
    UILabel *title_label = [[UILabel alloc] init];
    title_label.text = @"发布";
    title_label.font = [UIFont systemFontOfSize:12];
    title_label.textColor = RGB(255, 255, 255);
    title_label.textAlignment = NSTextAlignmentCenter;
    [self.fb_button addSubview:title_label];
    
    [image_v mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(title_label.mas_top);
        make.left.mas_equalTo(17);
        make.width.mas_equalTo(24);
        make.height.mas_equalTo(25);
        
        
    }];
    
    [title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(-6);
        make.left.and.right.mas_equalTo(0);
        make.height.mas_equalTo(12);
        
    }];
    
    
}

#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
//    return self.home_bmsh_array.count;
    return 3;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifity1 = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifity1];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifity1 ];
    }
    
    cell.textLabel.font = [UIFont systemFontOfSize:12.0f];
    cell.textLabel.textColor = RGB(102, 102, 102);
    cell.textLabel.text = @"幸福家园2栋6层601出售啦，联系电话：15012345678";
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return k_bmsh_view_h / 3;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


#pragma mark 私有方法 -- get
-(UITableView *)tabel_view{
    
    if (_tabel_view == nil) {
        _tabel_view = [[UITableView alloc] init];
        _tabel_view.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tabel_view.delegate = self;
        _tabel_view.dataSource = self;
    }
    return _tabel_view;
}

-(UIButton *)fb_button{
    
    if (_fb_button == nil) {
        _fb_button = [[UIButton alloc] init];
        [_fb_button setBackgroundColor:RGB(231, 157, 62)];
        _fb_button.layer.masksToBounds = YES;
        _fb_button.layer.cornerRadius = 3;
        
    }
    return _fb_button;
}

#pragma mark 对外方法
-(void)setHome_bmsh_array:(NSMutableArray *)home_bmsh_array{
    
    _home_bmsh_array = home_bmsh_array;
    [self.tabel_view reloadData];
    
}
@end
